﻿package
{
	import com.citrusengine.core.CitrusEngine;
	import com.citrusengine.objects.platformer.Baddy;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import com.citrusengine.core.State;
	import com.citrusengine.math.MathVector;
	import com.citrusengine.objects.CitrusSprite;
	import com.citrusengine.objects.PhysicsObject;
	import com.citrusengine.objects.platformer.Hero;
	import com.citrusengine.physics.Box2D;
	import com.citrusengine.utils.ObjectMaker;
	import com.citrusengine.objects.platformer.Coin;
	import com.citrusengine.objects.platformer.Platform;
	import flash.geom.*;  
	import flash.events.*;
	import flash.display.*;
	import flash.net.*;
    import flash.system.*;
    import flash.ui.*;

	
	/**
	 * ...
	 * @author Seven Game Studio
	 */
	public class Main extends CitrusEngine
	{
		public var gameState: 	Level;
		private var myLoader: 	URLLoader;
		private var level: 		XML;
		//public var stage.fullScreenSourceRect(new Rectangle(0, 0, 640, 480));
		//Citrus Engine
		public var ce:CitrusEngine;
		
		public function Main():void 
		{
			super();
			
			if (stage)
			{
				
				init()
			}
			else 
			{
				addEventListener(Event.ADDED_TO_STAGE, init);
			}
			
			//Array que contem todas as classes utilizadas no level.
			var classes:Array = [CitrusSprite, Coin, Hero, PhysicsObject, Platform, Baddy, Vald];
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			myLoader = new URLLoader();
			//Ao completar de carregar, executa função processXML
			myLoader.addEventListener(Event.COMPLETE, loadLevel);
			//carrega o xml com o nome da classe    
			myLoader.load(new URLRequest("RocketLVL01.lev")); 
			stage.scaleMode = StageScaleMode.EXACT_FIT;
			stage.displayState = "fullScreen";
			stage.align = StageAlign.TOP_LEFT;
			stage.fullScreenSourceRect = new Rectangle(0,0,800,500);
		}
		private function loadLevel(Evento:Event):void
		{
			//recebe o XML por parâmetro
			level = new XML(Evento.target.data);
			//Carrega o level
			state = new Level(level);
		}
	}
	
}